package org.personal.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	/**判断strs集合内是否存在NULL值或""值(不包括" "),存在则返回真,否则假
	 * @param strs 字符串集合
	 * @return true|false
	 */
	public static boolean isEmptyOrNull(Object...objs){
		for (int i = 0; i < objs.length; i++) {
			Object obj=objs[i];
			if(obj==null||obj.toString().trim().isEmpty())return true;
		}
		return false;
	}
	
	/** 截取指定长度的分段字符串
	 * @param src 字符串源
	 * @param interval 指定长度
	 * @return 分段字符的的集合
	 * @throws IllegalArgumentException 当interval>src.length
	 */
	public static List<String> cutString(String src,int interval) throws IllegalArgumentException{
		List<String> result=new ArrayList<String>();
		int len=0;
		if(!isEmptyOrNull(src)){
			String copySrc=src;
			len=copySrc.length();
			if(interval>len)throw new IllegalArgumentException();
			do{
				int copyStcLen=0;
				result.add(copySrc.substring(0,interval));
				copySrc=copySrc.substring(interval);
				copyStcLen=copySrc.length();
				if(copyStcLen<interval)interval=copyStcLen;
			}while(copySrc.length()!=0);
		}
		return result;
	}
	
	/** 是否是正确的电子邮箱地址
	 * @param email 
	 * @return
	 */
	public static boolean isEmail(String email){
		String regex ="^\\w+\\.?\\w+@\\w+(\\.\\w{2,3})+$";
		    Pattern   pattern   =   Pattern.compile(regex);     
		    Matcher   matcher   =   pattern.matcher(email);     
		    return matcher.find(); 
	}
	
	public static void main(String[] args) {
		System.out.println(StringUtil.isEmail("ffsf.ds.ccd545_h@fd3_nd.com.cd"));
	}
}
